//
//  LeisureTimeController.m
//  庐山通
//
//  Created by mac22 on 14/10/19.
//  Copyright (c) 2014年 郑朝军. All rights reserved.
//

#import "LeisureTimeController.h"
#import "Grouble.h"
#import "LeisureTitle.h"
#import "FindViewController.h"
#import "GoodViewController.h"
#import "ChooseViewController.h"
#import "TravelViewController.h"
#import "MyNavigation.h"

@interface LeisureTimeController()<LeisureTitleDelegate,UIScrollViewDelegate>
@property (nonatomic,strong) NSMutableArray *childViews;
@property (nonatomic,weak)LeisureTitle * leiTitle;
@property (nonatomic,weak)UIScrollView * myScrollerView;
@property (nonatomic,weak)FindViewController * find;
@property (nonatomic,weak)GoodViewController * good;
@property (nonatomic,weak)ChooseViewController * choose;

@end
@implementation LeisureTimeController
- (NSMutableArray *)childViews
{
    if (_childViews == nil) {
        _childViews = [[NSMutableArray alloc]init];
        
    }
    return _childViews;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createItem];
    [self setTitleItem];
    [self createScroller];
}
- (void)createScroller
{
    FindViewController * find = [[FindViewController alloc]init];
    [self addChildViewController:find];
    GoodViewController * good = [[GoodViewController alloc]init];
    
    [self addChildViewController:good];
     ChooseViewController * choose = [[ChooseViewController alloc]init];
    // 把子控制器放到集合中去
    [self addChildViewController:choose];
    
    [self.childViews addObject:find.view];
    [self.childViews addObject:good.view];
    [self.childViews addObject:choose.view];
    
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];
    scrollView.delegate=self;
    [self.view addSubview:scrollView];
    for(int i=0;i<self.childViews.count;i++){
        CGFloat childVX=ScreenWidth*i;
        UIView *childV=self.childViews[i];
        childV.frame=CGRectMake(childVX, 0, ScreenWidth, self.view.height);
        [scrollView addSubview:childV];
    }
    
   
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.showsVerticalScrollIndicator=NO;
    scrollView.pagingEnabled=YES;
    // 3个控制器
    scrollView.contentSize=CGSizeMake(ScreenWidth*3, 0);
    scrollView.bounces=NO;
    self.myScrollerView = scrollView;   
}

// 通知这个title改变
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
     NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
    if(scrollView.contentOffset.x/ScreenWidth==0){
        [self.leiTitle titleChange:0];
    }else if(scrollView.contentOffset.x/ScreenWidth==1){
        [self.leiTitle titleChange:1];
    }else if(scrollView.contentOffset.x/ScreenWidth==2){
        [self.leiTitle titleChange:2];
    }
}
- (void)setTitleItem
{
    LeisureTitle * leiView = [[LeisureTitle alloc]init];
    
    leiView.frame = CGRectMake(0, 0, 200, 30);
    leiView.delegate = self;
    self.navigationItem.titleView = leiView;
    self.leiTitle = leiView;
    
    
}
// 更换scroolView
- (void)LeisureTitleClick:(LeisureTitle *)myLeisure scroolIndex:(NSInteger)indexTop
{//调用以下函数，来自动滚动到想要的位置，此过程中设置有动画效果，停止时，触发该函数
    [self.myScrollerView scrollRectToVisible:CGRectMake(ScreenWidth * indexTop, 0, self.view.width, self.view.height) animated:YES];
}
- (void)createItem
{
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithIcon:@"all" highIcon:@"all_select" target:self action:@selector(sercher)];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"travle" highIcon:@"travle" target:self action:@selector(travel)];
}
// 旅游
- (void)travel
{
    TravelViewController * travletContRoller = [[TravelViewController alloc]init];
    MyNavigation * myNavgation = [[MyNavigation alloc]initWithRootViewController:travletContRoller];
    
    
    [self presentViewController:myNavgation animated:YES completion:nil];
    

}
- (void)sercher
{
    ZCJLog(@"ldjflk");
}
@end
